package think.thread.deadlock.c01;


public class Philosophers5Thread {

	public static void main(String[] args) throws Exception {
		int personSize = 2;
		int time = 0;
		Chopstick[] chopsticks = initChopsticks(personSize);

		Philosopher[] philosophers = new Philosopher[personSize];
		for (int i = 0; i < personSize; i++) {
			philosophers[i] = new Philosopher(chopsticks[i], chopsticks[(i + 1)
					% personSize], i, time);
		}

		for (int i = 0; i < personSize; i++) {
			Thread thread=new Thread(philosophers[i]);
			thread.start();
		}
	}

	public static Chopstick[] initChopsticks(int size) {
		Chopstick[] chopsticks = new Chopstick[size];
		for (int i = 0; i < size; i++) {
			chopsticks[i] = new Chopstick();
		}
		return chopsticks;
	}

}
